package com.chencong.transform;

import com.chencong.env.FlinkTableEnv;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author chencong
 * @Description
 * @Date 8:19 下午 2021/8/17
 * @Param
 **/
public class KeyBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment streamTableEnvironment = FlinkTableEnv.getStreamTableEnvironment();
//        streamTableEnvironment.setParallelism(1);

        streamTableEnvironment
                .fromElements(10, 3, 5, 9, 20, 8)
                .keyBy(new KeySelector<Integer, String>() {
                    @Override
                    public String getKey(Integer integer) throws Exception {
                        return integer % 2 == 0 ? "偶数" : "奇数";
                    }
                })
                .print();
        streamTableEnvironment.execute();
    }
}
